package main.java.chessfootball.model.game;

/**
 * User: Igor
 * Date: 10.06.2011
 * Time: 22:07:10
 */
public class Team
{
	private Side side;
	private Uniform uniform;
	private Half half;
	private Player[] players;

	public Team(Side side, Uniform uniform, Half half, Player[] players)
	{
		this.side = side;
		this.uniform = uniform;
		this.half = half;
		this.players = players;
	}

	public boolean contains(Cell cell)
	{
		return getPlayer(cell) != null;
	}

	public void putPlayer(Cell cell)
	{
		int next = 0;
		for (int n = 0; n < players.length; n++ )
		{
			if (players[n] == null)
			{
				next = n;
				break;
			}
		}
		setPlayer(next + 1, cell);
	}

	public void putPlayer(int x, int y)
	{
		putPlayer(new Cell(x, y));
	}

	public void setPlayer(int num, Cell cell)
	{
		players[num-1] = new Player(this, cell, num);
	}

	public Player getPlayer(Cell cell)
	{
		for (Player player : players)
		{
			if ((player != null) && (cell.equals(player.getCell())))
			{
				return player;
			}
		}
		return null;
	}

	public Player getPlayer(int num)
	{
		return players[num - 1];
	}

	public Side getSide()
	{
		return side;
	}

	public Uniform getUniform()
	{
		return uniform;
	}

	public Half getHalf()
	{
		return half;
	}

	public Player[] getPlayers()
	{
		return players;
	}

	public int getPlayersCount()
	{
		int count = 0;
		for (Player player : players)
		{
			if (player != null)
			{
				count++;	
			}
		}
		return count;
	}

	public void setSide(Side side)
	{
		this.side = side;
	}

	public void setUniform(Uniform uniform)
	{
		this.uniform = uniform;
	}

	public void setHalf(Half half)
	{
		this.half = half;
	}

	public void setPlayers(Player[] players)
	{
		this.players = players;
	}
}
